package game;

import game.Room.Direction;

import java.util.List;


public class Player {
   
   private String name;
   private Room room;
   
   public Player(String name, Room room) {
      this.name = name;
      this.room = room;
      room.addPlayer(this);
   }
   
   public Room move(Direction d) {
      Room goRoom = room.get(d);
      if (goRoom == null) {
         System.out.println("Cannot move in this direction! " + d);
         return null;
      }
      room.removePlayer(this);
      room = goRoom;
      room.addPlayer(this);
      return room;
   }
   
   public void move(List<Character> dirs) {
      Room goRoom = null;
      for (char c : dirs) {
         if (c == 'N') {
            goRoom = move(Direction.NORTH);
         } else if (c == 'E') {
            goRoom = move(Direction.EAST);
         } else if (c == 'S') {
            goRoom = move(Direction.SOUTH);
         } else if (c == 'W') {
            goRoom = move(Direction.WEST);
         }
         if (goRoom == null) return;
      }
   }
   
   public Room getRoom() {
      return room;
   }
   
   public void setRoom(Room room) {
      this.room.removePlayer(this);
      this.room = room;
      room.addPlayer(this);
   }

   @Override
   public String toString() {
      return name;
   }
}
